package com.softeem.controller;

import com.softeem.entity.User;
import com.softeem.mapper.WorkOrderMapper;
import com.softeem.model.WorkOrderModel;
import com.softeem.service.UserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/userPage")
public class UserPageController {

    @Autowired
    private UserService userService;

    @Autowired
    private WorkOrderMapper orderMapper;

    @RequestMapping("/home")
    public String home(){
        return "user/home";
    }

    @RequestMapping("/newOrder")
    public String newOrder(){
        return "user/newOrder";
    }

    @RequestMapping("/nowOrder")
    public String nowOrder(){
        return "user/nowOrder";
    }

    @RequestMapping("/allOrder")
    public String allOrder(){
        return "user/allOrder";
    }

    @RequestMapping("/home2")
    public String home2(){
        return "home/user";
    }

    @RequestMapping("/detail")
    public String detail(@Param("id") Integer id,@Param("req") HttpServletRequest req){
        User user = userService.getUserById(id);
        req.getSession().setAttribute("checkUser",user);
        return "staff/userdetail";
    }

    @RequestMapping("/detailplus")
    public String detailplus(@Param("id") Integer id,@Param("req") HttpServletRequest req){
        User user = userService.getUserById(id);
        req.getSession().setAttribute("checkUser",user);
        return "staff/userdetail2";
    }

    @RequestMapping("/sendInfo")
    public String sendInfo(@Param("orderId") Integer orderId, @Param("req") HttpServletRequest req, @Param("resp") HttpServletResponse resp){
        WorkOrderModel workOrderModel = orderMapper.selectModelById(orderId);
        req.getSession().setAttribute("orderInfo",workOrderModel);
        System.out.println(workOrderModel);
        return "user/sendInfo";
    }

}
